/*
 * iShopPlace Project.
 */
package ishopplace.model.service.impl;

import ishopplace.model.businessobject.Order;
import ishopplace.model.dao.OrderDao;
import ishopplace.model.exception.iShopPlaceException;
import ishopplace.model.service.OrderService;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;


/**
 * The implementation of the <code>OrderService</code>.
 * <p>
 * Spring Framework is used to manage this service bean.
 * Since this class is not dependend on Spring API, 
 * it can be used outside the Spring IOC container.
 * 
 * @author <a href="mailto:derek@derekshen.com">Derek Y. Shen</a>
 * @see OrderService
 */
public class OrderServiceImpl implements OrderService {
	//the logger for this class
	private Log logger = LogFactory.getLog(this.getClass());
	
	//the CatalogDao used
	private OrderDao orderDao;
	
	/**
	 * Set the <code>OrderDao</code>.
	 * <p>
	 * It can be used by the Spring IOC container.
	 * 
	 * @param newOrderDao the OrderDao to be set
	 */
	public void setOrderDao(OrderDao newOrderDao) {
		this.orderDao = newOrderDao;
	}
	
	public void saveOrder(Order order) throws iShopPlaceException {
		try {
			this.orderDao.saveOrder(order);
		} catch (Exception e) {
			String msg = "Could not save order " + e.toString();
			this.logger.error(msg, e);
			throw new iShopPlaceException(msg, e);
		}
	}
	
	public Order getOrder(String orderId)throws iShopPlaceException {
		try {
			return this.orderDao.getOrder(orderId);
		} catch (Exception e) {
			String msg = "Could not get order " + e.toString();
			this.logger.error(msg, e);
			throw new iShopPlaceException(msg, e);
		}
	}
}
